package com.tte.common.controller;

import com.tte.common.model.po.User;
import com.tte.common.service.UserService;
import com.tte.common.model.tenum.ResultCode;
import com.tte.common.model.vo.ResultBean;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * LoginController
 * @Author: DongWH
 * @Date: 2022/4/24 16:49
 */
@Slf4j
@RestController
public class LoginController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public ResultBean login(HttpServletRequest request,@RequestBody User user){
        log.debug(" 传入参数: {}",user);
        if(StringUtils.isAnyEmpty(user.getcLoginName(),user.getcLoginPass())){
            log.debug("传入参数为空");
            return new ResultBean(ResultCode.PARAMETER_EMPTY);
        }
        User userResult = userService.login(user);
        if(null == userResult){
            return new ResultBean(ResultCode.DATA_EMPTY,"");
        }
        return new ResultBean(ResultCode.OK,user);
    }
}
